﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;

namespace AppEszköz.UserManagement
{
    public class User : IPrincipal, IIdentity
    {
        public int UserId { get; set; }
        public string UserName { get; set; }
        public string Email { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public UserStatus Status { get; set; }
        public string Name => UserName;
        public Login Login { get; }
        public IList<AccessRole>AccessRoles { get; set; }  
        public string AuthenticationType => "Windows";

        public IIdentity Identity => (IIdentity)this;

        public bool IsAuthenticated => Login.PasswordValid; 

        public bool IsInRole(string role)
        {
            return AccessRoles.Any(accessRole => accessRole.RoleName == role);
        }

        public User()
        {
            UserId = -1;
            Login = new Login();
        }
    }
}
